<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>removeTag</title>
  </head>
  <body>
    <ul id="ul">
      <li>段落1</li>
      <li>段落2</li>
      <li>段落3</li>
      <li>段落4</li>
      <li>段落5</li>
    </ul>
  </body>
</html>
<script>
  function removeTag(fragment) {
    const parser = new DOMParser()
    // parseFromString 将 HTML 字符串解析成 DOM 文档
    const dom = parser.parseFromString(fragment, 'text/html')
    const doc = dom?.body?.textContent
    return doc?.trim() || ''
  }
  const content = removeTag(document.getElementById('ul').innerHTML)
  console.log(content)
</script>
